package cc.miwuya.common.util;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author 迷雾森林
 * @Date 2024-01-08 21:16
 * 统一返回
 */
@Data
public class Result implements Serializable {

    private Integer code;
    private String msg;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Object data;

    public static Result success(){
        Result result = new Result();
        result.setCode(200);
        result.setMsg("操作成功");
        return result;
    }

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(200);
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }

    public static Result success(String msg){
        Result result = new Result();
        result.setCode(200);
        result.setMsg(msg);
        return result;
    }

    public static Result success(String msg,Object data){
        Result result = new Result();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result error(){
        Result result = new Result();
        result.setCode(-1);
        result.setMsg("操作失败");
        return result;
    }
    public static Result error(int code){
        Result result = new Result();
        result.setCode(code);
        result.setMsg("操作失败");
        return result;
    }
    public static Result error(String msg){
        Result result = new Result();
        result.setCode(-1);
        result.setMsg(msg);
        return result;
    }
    public static Result error(Object data){
        Result result = new Result();
        result.setCode(-1);
        result.setMsg("操作失败");
        result.setData(data);
        return result;
    }
    public static Result error(int code,Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg("操作失败");
        result.setData(data);
        return result;
    }
    public static Result error(int code,String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
    public static Result error(int code,String msg,Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}
